<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=\, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>111</div>
    <script>
        //普通函数this指向window
        function show(){
            console.log(this);
        }
        show();

        //构造函数this指向new的对象
        function Person(name, age){
            this.name=name;
            this.age=age;
            this.say=function(){
                console.log('说话');
                console.log(this);
            }
        }
        new Person.say();

        var p={
            say:function(){
                console.log(this);
            }
        }
        p.say();

        //事件绑定：this 指向事件源本身（元素）
        document.querySelector('div').addEventListener('click',function(){
            console.log(this);
        })

        //定时函数 this指向window
        setInterval(function() {
            console.log(this)
        }, 3000);

        //自执行函数 this指向window
        (function(){
            console.log(this);
        })();
    </script>
</body>
</html>